package com.tsing.bms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tsing.bms.entity.Depot;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
public interface DepotMapper extends BaseMapper<Depot> {

    @Select("<script>" +
            "select 1 from t_depot d\n" +
            "inner join t_carport c on d.id=c.depot_id\n" +
            "where d.id in\n" +
            "<foreach collection='ids' item='item' open='(' close=')' separator=',' >\n" +
            "#{item}\n" +
            "</foreach>\n" +
            "limit 1" +
            "</script>")
    String haveRelevance(@Param("ids") List<String> ids);

    @Select("select count(id)\n" +
            "from t_carport \n" +
            "where depot_id=#{id}")
    long findCarportCount(@Param("id") String id);

    @Select("select count(c.id)\n" +
            "from t_carport c\n" +
            "where depot_id=#{id} and status=2")
    long findCqyzCount(@Param("id") String id);

    @Select("select count(c.id)\n" +
            "from t_carport c\n" +
            "where depot_id=#{id} and status=0")
    long findCwzhCount(@Param("id") String id);

    @Select("select count(c.id)\n" +
            "from t_carport c\n" +
            "where depot_id=#{id} and status=1")
    long XzcwCount(@Param("id") String id);

}
